//
//  UIApplication+Extension.swift
//  GeekTime
//
//  Created by monkey on 2020/1/30.
//  Copyright © 2020 itcast. All rights reserved.
//

import UIKit

extension UIApplication
{
    private static let runOnce: Void = {
        NothingToSeeHere.harmlessFunction()
    }()

    override open var next: UIResponder? {
        // Called before applicationDidFinishLaunching
        UIApplication.runOnce
        return super.next
    }
}

protocol XGSelfAware: class
{
    static func awake()
}

class NothingToSeeHere
{
    static func harmlessFunction() {
        let typeCount = Int(objc_getClassList(nil, 0))
        let types = UnsafeMutablePointer<AnyClass>.allocate(capacity: typeCount)
        let safeTypes = AutoreleasingUnsafeMutablePointer<AnyClass>(types)
        objc_getClassList(safeTypes, Int32(typeCount))
        for index in 0 ..< typeCount {
            if let selfAwareType = types[index] as? XGSelfAware.Type {
                selfAwareType.awake()
            }
        }
        types.deallocate()
    }
}
